/obj/structure/janitorialcart
	name = "janitorial cart"
	desc = "This is the alpha and omega of sanitation."
	icon = 'icons/obj/janitor.dmi'
	icon_state = "cart"
	anchored = 0
	density = 1
	flags = OPENCONTAINER
	//copypaste sorry
	var/amount_per_transfer_from_this = 5 //shit I dunno, adding this so syringes stop runtime erroring. --NeoFite
	var/obj/item/weapon/storage/bag/trash/mybag	= null
	var/obj/item/weapon/mop/mymop = null
	var/obj/item/weapon/reagent_containers/spray/myspray = null
	var/obj/item/device/lightreplacer/myreplacer = null
	var/signs = 0	//maximum capacity hardcoded below


/obj/structure/janitorialcart/New()
	create_reagents(300)

/obj/structure/janitorialcart/prespawned/New()
	..()
	reagents.add_reagent("water", 150)
	reagents.add_reagent("ammonia", 150)
	mybag	= new/obj/item/weapon/storage/bag/trash
	mymop = new/obj/item/weapon/mop
	myspray = new/obj/item/weapon/reagent_containers/spray/cleaner
	myreplacer = new/obj/item/device/lightreplacer

/obj/structure/janitorialcart/examine()
	set src in usr
	usr << "[src] \icon[src] contains [reagents.total_volume] unit\s of liquid!"
	..()
	//everything else is visible, so doesn't need to be mentioned


/obj/structure/janitorialcart/attackby(obj/item/I, mob/user)
	if(istype(I, /obj/item/weapon/storage/bag/trash) && !mybag)
		user.drop_item()
		mybag = I
		I.loc = src
		update_icon()
		updateUsrDialog()
		user << "<span class='notice'>You put [I] into [src].</span>"

	else if(istype(I, /obj/item/weapon/mop))
		if(I.reagents.total_volume < I.reagents.maximum_volume)	//if it's not completely soaked we assume they want to wet it, otherwise store it
			if(reagents.total_volume < 1)
				user << "[src] is out of water!</span>"
			else
				reagents.trans_to(I, 5)	//
				user << "<span class='notice'>You wet [I] in [src].</span>"
				playsound(loc, 'sound/effects/slosh.ogg', 25, 1)
				return
		if(!mymop)
			user.drop_item()
			mymop = I
			I.loc = src
			update_icon()
			updateUsrDialog()
			user << "<span class='notice'>You put [I] into [src].</span>"

	else if(istype(I, /obj/item/weapon/reagent_containers/spray) && !myspray)
		user.drop_item()
		myspray = I
		I.loc = src
		update_icon()
		updateUsrDialog()
		user << "<span class='notice'>You put [I] into [src].</span>"

	else if(istype(I, /obj/item/device/lightreplacer) && !myreplacer)
		user.drop_item()
		myreplacer = I
		I.loc = src
		update_icon()
		updateUsrDialog()
		user << "<span class='notice'>You put [I] into [src].</span>"

	else if(istype(I, /obj/item/weapon/caution))
		if(signs < 4)
			user.drop_item()
			I.loc = src
			signs++
			update_icon()
			updateUsrDialog()
			user << "<span class='notice'>You put [I] into [src].</span>"
		else
			user << "<span class='notice'>[src] can't hold any more signs.</span>"

	else if(mybag)
		mybag.attackby(I, user)


/obj/structure/janitorialcart/attack_hand(mob/user)
	user.set_machine(src)
	var/dat
	if(mybag)
		dat += "<a href='?src=\ref[src];garbage=1'>[mybag.name]</a><br>"
	if(mymop)
		dat += "<a href='?src=\ref[src];mop=1'>[mymop.name]</a><br>"
	if(myspray)
		dat += "<a href='?src=\ref[src];spray=1'>[myspray.name]</a><br>"
	if(myreplacer)
		dat += "<a href='?src=\ref[src];replacer=1'>[myreplacer.name]</a><br>"
	if(signs)
		dat += "<a href='?src=\ref[src];sign=1'>[signs] sign\s</a><br>"
	var/datum/browser/popup = new(user, "janicart", name, 240, 160)
	popup.set_content(dat)
	popup.open()


/obj/structure/janitorialcart/Topic(href, href_list)
	if(!in_range(src, usr))
		return
	if(!isliving(usr))
		return
	var/mob/living/user = usr
	if(href_list["garbage"])
		if(mybag)
			user.put_in_hands(mybag)
			user << "<span class='notice'>You take [mybag] from [src].</span>"
			mybag = null
	if(href_list["mop"])
		if(mymop)
			user.put_in_hands(mymop)
			user << "<span class='notice'>You take [mymop] from [src].</span>"
			mymop = null
	if(href_list["spray"])
		if(myspray)
			user.put_in_hands(myspray)
			user << "<span class='notice'>You take [myspray] from [src].</span>"
			myspray = null
	if(href_list["replacer"])
		if(myreplacer)
			user.put_in_hands(myreplacer)
			user << "<span class='notice'>You take [myreplacer] from [src].</span>"
			myreplacer = null
	if(href_list["sign"])
		if(signs)
			var/obj/item/weapon/caution/Sign = locate() in src
			if(Sign)
				user.put_in_hands(Sign)
				user << "<span class='notice'>You take \a [Sign] from [src].</span>"
				signs--
			else
				warning("[src] signs ([signs]) didn't match contents")
				signs = 0

	update_icon()
	updateUsrDialog()


/obj/structure/janitorialcart/update_icon()
	overlays = null
	if(mybag)
		overlays += "cart_garbage"
	if(mymop)
		overlays += "cart_mop"
	if(myspray)
		overlays += "cart_spray"
	if(myreplacer)
		overlays += "cart_replacer"
	if(signs)
		overlays += "cart_sign[signs]"


//old style retardo-cart //Not anymore, replaced it with HOVERBIKES. BEEP BOOP.
/obj/structure/stool/bed/chair/motorcycle
	name = "captain's hoverbike"
	desc = "The seat smells of a comdom! Still a pimpin' ride though."
	icon = 'icons/obj/vehicles.dmi'
	icon_state = "cap_hoverbike"
	var/health = 150
	anchored = 1
	density = 1

/obj/structure/stool/bed/chair/motorcycle/attackby(obj/item/W, mob/user)
	if(istype(W, /obj/item/key))
		user << "Hold [W] in one of your hands while you drive this pimpin' ride."

/obj/structure/stool/bed/chair/motorcycle/bullet_act(var/obj/item/projectile/Proj)
	if(buckled_mob)
		if(prob(85))
			return buckled_mob.bullet_act(Proj)
	visible_message("<span class='warning'>[Proj.name] directly hits [src.name]!</span>")
	src.health -= rand(25,60)
	if(src.health < 0)
		unbuckle()
		del(src)

/obj/structure/stool/bed/chair/motorcycle/relaymove(mob/user, direction)
	if(user.stat || user.stunned || user.weakened || user.paralysis)
		unbuckle()
	if(istype(user.l_hand, /obj/item/key) || istype(user.r_hand, /obj/item/key))
		step(src, direction)
		update_mob()
		handle_rotation()
	else
		user << "<span class='notice'>You'll need the keys in one of your hands to drive this pimpin' ride.</span>"

/obj/structure/stool/bed/chair/motorcycle/Move()
	..()
	if(buckled_mob)
		if(buckled_mob.buckled == src)
			buckled_mob.loc = loc

/obj/structure/stool/bed/chair/motorcycle/buckle_mob(mob/M, mob/user)
	if(M != user || !ismob(M) || get_dist(src, user) > 1 || user.restrained() || user.lying || user.stat || M.buckled || istype(user, /mob/living/silicon))
		return
	unbuckle()

	M.visible_message(\
		"<span class='notice'>[M] clambers onto the hoverbike.</span>",\
		"<span class='notice'>You clamber onto the hoverbike.</span>")
	M.buckled = src
	M.loc = loc
	M.dir = dir
	M.update_canmove()
	buckled_mob = M
	update_mob()
	add_fingerprint(user)
	return



/obj/structure/stool/bed/chair/motorcycle/handle_rotation()
	if(dir == SOUTH)
		layer = FLY_LAYER
	else if(dir == NORTH)
		layer = FLY_LAYER
	else
		layer = MOB_LAYER

	if(buckled_mob)
		if(buckled_mob.loc != loc)
			buckled_mob.buckled = null //Temporary, so Move() succeeds.
			buckled_mob.buckled = src //Restoring

	update_mob()

/obj/structure/stool/bed/chair/motorcycle/proc/update_mob()
	if(buckled_mob)
		buckled_mob.dir = dir

/obj/structure/stool/bed/chair/motorcycle/sec
	name = "security hoverbike"
	desc = "Driven by the 5-0."
	icon_state = "sec_hoverbike"

/obj/structure/stool/bed/chair/motorcycle/sec/attackby(obj/item/W, mob/user)
	if(istype(W, /obj/item/key/sec))
		user << "Hold [W] in one of your hands while you drive this hoverbike."

/obj/structure/stool/bed/chair/motorcycle/sec/relaymove(mob/user, direction)
	if(user.stat || user.stunned || user.weakened || user.paralysis)
		unbuckle()
	if(istype(user.l_hand, /obj/item/key/sec) || istype(user.r_hand, /obj/item/key/sec))
		step(src, direction)
		update_mob()
		handle_rotation()
	else
		user << "<span class='notice'>You'll need the keys in one of your hands to drive this robust ride.</span>"

/obj/structure/stool/bed/chair/motorcycle/eng
	name = "engineering hoverbike"
	desc = "Driven by the Drunks."
	icon_state = "eng_hoverbike"
	health = 75

/obj/structure/stool/bed/chair/motorcycle/eng/attackby(obj/item/W, mob/user)
	if(istype(W, /obj/item/key/eng))
		user << "Hold [W] in one of your hands while you drive this hoverbike."

/obj/structure/stool/bed/chair/motorcycle/eng/relaymove(mob/user, direction)
	if(user.stat || user.stunned || user.weakened || user.paralysis)
		unbuckle()
	if(istype(user.l_hand, /obj/item/key/eng) || istype(user.r_hand, /obj/item/key/eng))
		step(src, direction)
		update_mob()
		handle_rotation()
	else
		user << "<span class='notice'>You'll need the keys in one of your hands to drive this shocking ride.</span>"

/obj/structure/stool/bed/chair/motorcycle/syn
	name = "suspicious hoverbike"
	desc = "Probably driven by a murderer... or not?"
	icon_state = "syn_hoverbike"
	health = 175

/obj/structure/stool/bed/chair/motorcycle/syn/attackby(obj/item/W, mob/user)
	if(istype(W, /obj/item/key/syn))
		user << "Hold [W] in one of your hands while you drive this hoverbike."

/obj/structure/stool/bed/chair/motorcycle/syn/relaymove(mob/user, direction)
	if(user.stat || user.stunned || user.weakened || user.paralysis)
		unbuckle()
	if(istype(user.l_hand, /obj/item/key/syn) || istype(user.r_hand, /obj/item/key/syn))
		step(src, direction)
		update_mob()
		handle_rotation()
	else
		user << "<span class='notice'>You'll need the keys in one of your hands to drive this suspicious ride.</span>"

//The Keys
/obj/item/key
	name = "commander's hoverbike key"
	desc = "A blue and gold keyring with a small steel key. This one goes to the Commander's Hoverbike."
	icon = 'icons/obj/vehicles.dmi'
	icon_state = "cap_key"
	w_class = 1

/obj/item/key/sec
	name = "security hoverbike key"
	desc = "A red keyring with a small steel key. This one goes to Security's Hoverbikes."
	icon_state = "sec_key"

/obj/item/key/eng
	name = "engineering hoverbike key"
	desc = "An orange keyring with a small steel key. This one goes to Engineering's Hoverbikes."
	icon_state = "eng_key"

/obj/item/key/syn
	name = "suspicious hoverbike key"
	desc = "A red and black keyring with a small steel key. This one is Suspicious looking."
	icon_state = "syn_key"

/obj/item/key/med
	name = "medical hoverbike key"
	desc = "A white keyring with a small steel key. This one probably goes to the sex addic- Er, Medbay's Hoverbikes."
	icon_state = "syn_key"